
--[[

    slimui - Copyright (c) 2011 atom0s, All rights reserved.

    See Copyright notice in slimui.lua
    
]]--

class 'Form: CustomControl' { ... }

----------------------------------------------------------------------------------
-- func: Form.__init__
-- desc: Constructor called when this object is first created.
----------------------------------------------------------------------------------
function Form.__init__( self )
    CustomControl.__init__( self );
end

----------------------------------------------------------------------------------
-- func: Form:Create
-- desc: Create a new form object.
----------------------------------------------------------------------------------
function Form:Create( bVisible )
    if bVisible == nil then bVisible = true; end

    self._object = createForm( bVisible );
    
    if self._object == nil then
        slimui:err( 'Form:Create failed to initialize a new form object.' );
    end
    
    return self;
end

----------------------------------------------------------------------------------
-- func: Form:CreateFromFile
-- desc: Create a new form object from the given file.
----------------------------------------------------------------------------------
function Form:CreateFromFile( filename )
    if filename == nil then return; end
    
    -- Todo : add some file checks here..
    
    self._object = createFormFromFile( filename );
    
    if self._object == nil then
        slimui:err( 'Form:Create failed to initialize a new form object.' );
    end
    
    return self;
end

----------------------------------------------------------------------------------
-- func: Form:SaveToFile
-- desc: Save this form object to a file.
----------------------------------------------------------------------------------
function Form:SaveToFile( filename )
    if filename == nil then return false; end
    
    -- Todo : add some file checks here..
    
    form_saveToFile( self._object, filename );
    
    return true;
end

-----------------------------------------------------------------------------
-- func: Form:CenterScreen
-- desc: Places this form at the center of the screen.
-----------------------------------------------------------------------------
function Form:CenterScreen( )
    form_centerScreen( self._object );
end

-----------------------------------------------------------------------------
-- func: Form:Hide
-- desc: Hides this form.
-----------------------------------------------------------------------------
function Form:Hide( )
    form_hide( self._object );
end

-----------------------------------------------------------------------------
-- func: Form:Show
-- desc: Shows this form.
-----------------------------------------------------------------------------
function Form:Show( )
    form_show( self._object );
end

-----------------------------------------------------------------------------
-- func: Form:ShowModal
-- desc: Show this form and wait for it to close. (Modal state.)
-----------------------------------------------------------------------------
function Form:ShowModal( )
    form_showModal( self._object );
end

-----------------------------------------------------------------------------
-- func: Form:IsForegroundWindow
-- desc: Returns whether or not this form is the foreground window.
-----------------------------------------------------------------------------
function Form:IsForegroundWindow( )
    return form_isForegroundWindow( self._object );
end

-----------------------------------------------------------------------------
-- func : Form:OnClose
-- desc : Sets this forms OnClose event handler.
-----------------------------------------------------------------------------
function Form:OnClose( func )
    form_onClose( self._object, func );
end

-----------------------------------------------------------------------------
-- func : Form:GetMenu
-- desc : Returns this forms menu object.
-----------------------------------------------------------------------------
function Form:GetMenu( )
    return form_getMenu( self._object );
end

-----------------------------------------------------------------------------
-- func : Form:SetMenu
-- desc : Sets this forms menu object.
-----------------------------------------------------------------------------
function Form:SetMenu( menu )
    form_setMenu( self._object, menu );
end

-----------------------------------------------------------------------------
-- func : Form:GetSaveInTable
-- desc : Returns the DoNotSaveInTable property of this form.
-----------------------------------------------------------------------------
function Form:GetSaveInTable( )
    return form_getDoNotSaveInTable( self._object );
end

-----------------------------------------------------------------------------
-- func : Form:SetSaveInTable
-- desc : Sets the DoNotSaveInTable property of this form.
-----------------------------------------------------------------------------
function Form:SetSaveInTable( donotsave )
    form_setDoNotSaveInTable( self._object, donotsave );
end



--[[ Debug information. ]]--------------------------------------------------------
if ( slimui:isdebug() == true ) then
    slimui:msg( '(Control) form.lua successfully loaded.' );
end